import Vue from 'vue'
import Router from 'vue-router'
import Login from './views/login.vue'
import Home from './views/home.vue'

Vue.use(Router)

const router = new Router({
  // mode: 'history',
  mode: 'hash',
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/home',
      component: Home,
      redirect: '/welcome',
      children: [
        {
          path: '/welcome',
          component: () => import('./components/welcome.vue')
        },
        {
          path: '/goods/goodsList',
          component: () => import('./components/goods/goodsList')
        },
        {
          path: '/goods/goodsCate',
          component: () => import('./components/goods/goodsCate')
        },
        {
          path: '/goods/brands',
          component: () => import('./components/goods/brands')
        },
        {
          path: '/outGoods/outGoodsList',
          component: () => import('./components/outGoods/outGoodsList')
        },
        {
          path: '/orders/ordersList',
          component: () => import('./components/orders/ordersList')
        },
        {
          path: '/splitOrder/splitList',
          component: () => import('./components/splitOrder/splitList')
        },
        {
          path: '/orders/ordersSet',
          component: () => import('./components/orders/ordersSet')
        },
        {
          path: '/seting/user',
          component: () => import('./components/seting/user')
        },
        {
          path: '/seting/roles',
          component: () => import('./components/seting/role')
        },
        {
          path: '/quan/quanList',
          component: () => import('./components/quan/quanList')
        }
      ]
    }
  ]
})
// 配置导航守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  let str = window.sessionStorage.getItem('token')
  if (!str) return next('/login')
  next()
})
export default router
